package org.starapp.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;

public class FileUtils {
	public static String getStringFromInputStream(InputStream in) {
		try {
			// 显示数据记录内容
			BufferedReader br = new BufferedReader(new InputStreamReader(in,
					"UTF-8"));
			String str = "";// in.readLine();
			StringBuffer s = new StringBuffer("");
			while ((str = br.readLine()) != null) {
				s.append(str);
			}
			br.close();
			return s.toString();
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	@SuppressWarnings( { "unchecked", "deprecation" })
	public static String getPath(Class cls) {
		return java.net.URLDecoder.decode(cls.getClassLoader().getResource("/")
				.getPath());
	}

	@SuppressWarnings("deprecation")
	public static String getProjectPath() {
		return java.net.URLDecoder.decode(System.getProperty("user.dir"));
	}

	@SuppressWarnings("deprecation")
	public static String getSrcPath() {
		return java.net.URLDecoder.decode(getProjectPath() + File.separator
				+ "src");
	}

	@SuppressWarnings( { "unchecked", "deprecation" })
	public static String getFullPath(Class cls) {
		return java.net.URLDecoder.decode(cls.getResource("").getPath()
				+ cls.getSimpleName() + ".class");
	}
}
